import time
import unittest
from selenium import webdriver
from selenium.webdriver.common.by import By
# 导入鼠标事件的包
# 导入封装的Tools类
from unit__002.unit__004.Tools import Tools
from ddt import ddt,unpack,data
from unit__002.unit__004.excel import excel

path = r'/unit__002/unit__004/data.xlsx'
sheetname = 'Sheet1'
db = excel(path, sheetname)

@ddt
class MyTestCase(unittest.TestCase):
    def setUp(self) -> None:
        print('start case')
        Tools().Log()
        self.driver = webdriver.Edge()
        self.driver.get('https://www.ctrip.com/')
        self.driver.maximize_window()

    def tearDown(self) -> None:
        print('end case')
        time.sleep(5)
        self.driver.quit()

    @data(*db.get_data())
    @unpack
    def test_ctrip_01(self,username,password,hopt):
        time.sleep(5)
        # 1.点击登录
        self.driver.find_element(By.CLASS_NAME,'tl_nfes_home_header_login_not_frb4a').click()
        time.sleep(2)
        # 2.输入账号
        phone = self.driver.find_element(By.XPATH, '//*[@id="bbz_accounts_pc_lg_box"]/div/div/div[1]/div[1]/form/dl[1]/dd/input')
        phone.send_keys(username)
        time.sleep(2)
        # # 鼠标单击事件
        # ActionChains(self.driver).click(phone).perform()
        # time.sleep(2)
        # # 鼠标双击事件
        # ActionChains(self.driver).double_click(phone).perform()
        # time.sleep(2)
        # # 鼠标三击事件
        # ActionChains(self.driver).double_click(phone).click(phone).perform()
        # time.sleep(2)
        # 3.输入密码
        self.driver.find_element(By.XPATH, '//*[@id="bbz_accounts_pc_lg_box"]/div/div/div[1]/div[1]/form/dl[2]/dd/input').send_keys(password)
        time.sleep(3)
        # 4.勾选协议
        self.driver.find_element(By.XPATH, '/html/body/div[1]/div[2]/div[2]/div[2]/div/div/div[1]/div[4]/div/div[1]/label').click()
        time.sleep(2)
        # 5.点击登录
        self.driver.find_element(By.XPATH, '//*[@id="bbz_accounts_pc_lg_box"]/div/div/div[1]/div[1]/form/dl[3]/dd/input').click()
        if hopt == '反':
            # 断言
            time.sleep(10)
            dy = self.driver.find_element(By.CLASS_NAME,'base_error').text
            self.assertEqual('用户名或密码不正确(90014)',dy)
        else:
            return
            # 断言
            # time.sleep(10)
            # dy = self.driver.find_element(By.XPATH, '//*[@id="bbz_accounts_pc_lg_box"]/div/div/div[1]/h2/text()').text
            # self.assertEqual('账号密码登录', dy)



if __name__ == '__main__':
    unittest.main()
